package stack;

/**
 * 用栈实现队列 -232
 *
 * @author yyz
 * @create 2024-01-03 19:56
 */
public class Leetcode232 {
    private final ArrayStack<Integer> s1 = new ArrayStack<>(100);// 队头
    private final ArrayStack<Integer> s2 = new ArrayStack<>(100);// 队尾

    public void push(int x) {
        s2.push(x);
    }

    public int pop() {
        if (s1.isEmpty()) {
            while (!s2.isEmpty()) {
                s1.push(s2.pop());
            }
        }
        return s1.pop();
    }

    public int peek() {
        if (s1.isEmpty()) {
            while (!s2.isEmpty()) {
                s1.push(s2.pop());
            }
        }
        return s1.peek();
    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }
}
